<?php
namespace app\pc\controller;
use service\CacheService;
use service\JsonService;
use service\SystemConfigService;
use service\UtilService;
use think\Cookie;
use think\Request;
use think\Session;
use think\Url;
use app\pc\model\user\User;
use app\pc\model\user\MemberShip;
use app\pc\model\tindex\Catehome as catehomemodel;
use app\pc\model\myt\Mycuoti;
use app\pc\model\myt\Mybiji;
use app\pc\model\myt\Myfav;
use app\pc\model\tindex\Tquestion;
class Myt extends AuthController
{

    /*
 * 白名单
 * */
    public static function WhiteList()
    {
        return [
            'member_recharge'
        ];
    }
    protected function _initialize()
    {
    
        parent::_initialize();
        $this->cateid=$cateid=$this->request->param('cateid');
        $this->isopen();
    }
  
    public  function mycuoti(){
        $item= $this->item;
        $data=Mycuoti::getAll(array("userid"=>$this->uid,"limit"=>20));
        $page = $data->render();
        $this->assign('list',$data);
        $this->assign('page', $page);
        $this->assign('item',$item);
        return $this->fetch();
    }
    public function deletecuoti($id){
        Mycuoti::deleteData(array("userid"=>$this->uid,"id"=>$id));
        echo "<script>alert('删除成功');window.history.go(-1);</script>";
    }
    public  function myfav(){
        $item= $this->item;
        $data=Myfav::getAll(array("userid"=>$this->uid,"limit"=>20));
        $page = $data->render();
        $this->assign('list',$data);
        $this->assign('page', $page);
        $this->assign('item',$item);
        return $this->fetch();
    }
    public function deletefav($id){
        Myfav::deleteData(array("userid"=>$this->uid,"id"=>$id));
        echo "<script>alert('删除成功');window.history.go(-1);</script>";
    }
    public function mybiji(){
        $item= $this->item;
        $data=Mybiji::getAll(array("userid"=>$this->uid,"limit"=>20));
        $page = $data->render();
        $this->assign('list',$data);
        $this->assign('page', $page);
        $this->assign('item',$item);
        return $this->fetch();
    }
    public function deletebiji($id){
        Mybiji::deleteData(array("userid"=>$this->uid,"id"=>$id));
        echo "<script>alert('删除成功');window.history.go(-1);</script>";
    }

    public function tqueview()
    {
        $post=$this->request->post();
        $item= $this->item;
        $data=Tquestion::getinfos($post,$item["fix"]);
 
        $this->assign('item',$item);
        $this->assign('data',$data);
        return $this->fetch();
    }
    public function tuiguang(){

        $uids = User::where('spread_uid', $this->uid)->group('uid')->column('uid');
        $data['one_spread_count'] = count($uids);
        if ($data['one_spread_count']) {
            $data['order_count'] = UserBill::where(['u.paid' => 1, 'u.is_del' => 0])->where('a.category', 'now_money')->where('a.type', 'in', ['brokerage'])->group('u.id')->where('a.uid', 'in', $uids)->join("__STORE_ORDER__ u", 'u.id=a.link_id')->alias('a')->count();
        } else {
            $data['order_count'] = 0;
        }

        $data['spread_count'] = User::whereTime('spread_time', 'today')->where('is_promoter', 1)->where('spread_uid', $this->uid)->count();
        $this->assign('promoter_content', SystemConfigService::get('promoter_content'));
        $this->assign('item',$this->item);
        $this->assign("speadurl","http://".$_SERVER['HTTP_HOST'].Url::build('login/index',array("spread_uid"=>$this->uid)));
        $this->assign('data', $data);
        return $this->fetch();
    }

}